Floor, Ceiling, and Log floor - round down to nearest whole number ceiling - round up to nearest whole number log10(x) = ? What power would I need to raise 10 to to equal x log10(1000) = 3 log10(5000) = 3.7 log2(x) - What power would I need to raise 2 to to equal x log2(1024) = 10 log2(5000) = 12.29 log2(1024*1024) = 20 log2(1024*1024*1024) = 30 log(x) grows much more slowly than x How many bits to represent decimal number N in binary? floor(log2(N)) + 1 1 bit: 0-1 2-bits: 0-3 3-bits: 0-7 4-bits: 0-15 5-bits: 0-31 Repeated Doubling: If we set X = 1, how many times can we double X before it becomes greater than or equal to N? ceiling(log2(N)) Repeated Halving: If we set X to N, how many times can we halve X before it becomes less than or equal to 1? ceiling(log2(N)) Search(Array, Value) return index of Value, or -1 Sequential Search unsorted data unsuccessful search always n successful search worst-case: n average-case: n/2 Binary Search iterative unsuccessful search always floor(log2(N)) + 1 successful search worst-case: floor(log2(N)) average-case: floor(log2(N)) - 1 If binary search is so fast, why would we ever need any other search algorithm? It assumes a sorted array, which is hard to maintain efficiently if the set of values is dynamic recursive modified binary search that returns the position where the value would have been if it were in there (final value of low) Java binarySearch Boggle dictionary implementation prefix pruning